﻿using GibbsLDASharp.LDA;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GibbsLDASharp
{
    class Program
    {
        static void Main(string[] args)
        {
            LDACmdOption option = new LDACmdOption();
            CmdLineParser parser = new CmdLineParser(option);

            try
            {
                if (args.Length == 0)
                {

                    ShowHelp(parser);
                    return;
                }

                parser.ParseCommandLine(args);

                if (option.est || option.estc)
                {
                    Estimator estimator = new Estimator();
                    estimator.Initialize(option);
                    estimator.Estimate();
                }
                else if (option.inf)
                {
                    Inferencer inferencer = new Inferencer();
                    inferencer.Init(option);

                    Model newModel = inferencer.Inference();

                    for (int i = 0; i < newModel.phi.Length; ++i)
                    {
                        //phi: K * V
                        Console.WriteLine("-----------------------\ntopic" + i + " : ");
                        for (int j = 0; j < 10; ++j)
                        {
                            Console.WriteLine(inferencer.globalDict.id2word[j] + "\t" + newModel.phi[i, j]);
                        }
                    }

                }
                Console.ReadKey();
            }
            catch (Exception cle)
            {
                Console.WriteLine("Command line error: " + cle.Message);
                ShowHelp(parser);
                return;
            }
        }
        public static void ShowHelp(CmdLineParser parser)
        {
            parser.ShowUsages();
            Console.Write("Press any key to continue...");
            Console.ReadKey();
            //parser.printUsage(System.out);
        }
    }
}
